<%@page language="java" contentType="text/html; charset=utf-8"%>
<%@include file="/tagDeclare.jsp"%>
<%@include file="/headDeclare.jsp"%>
<html>
<head>
<style type="text/css">
fieldset, legend, form, table, tr, td, textarea {
	margin: 0;
	padding: 0
}

form label {
	font-weight: bold;
}

table {
	margin: 10px 10px
}

;
td {
	line-height: 40px;
}

input[type="text"] {
	width: 250px;
}

input[type="password"] {
	width: 250px;
}

input[type="textarea"] {
	width: 250px;
}
</style>

<script type="text/javascript">
	var keep = "no";
	  $(document).ready(function(){
		     
		     $('#province').focus();
		     
		     $.ajaxSetup ({ cache:false,async: false });
		     
		   //异步提交表单
		     var options = {dataType: 'json', beforeSubmit: beforeSubmit, success: process};
		     $("#wallForm").submit(function(){
		         $(this).ajaxSubmit(options);
		          return false;
		     });
		     
		   //提交前验证
			   function beforeSubmit() {
				     if(isEmpty($("#province").val())) { alert("省份不能为空！"); return false; }
				     if(isEmpty($("#address").val())) { alert("地址不能为空！"); return false; }
				     if(isEmpty($("#high").val())) { alert("高度不能为空！"); return false; }
				     if(isEmpty($("#width").val())) { alert("宽度不能为空！"); return false; }
				     if(isEmpty($("#area").val())) { alert("面积不能为空！"); return false; }
				     if(isEmpty($("#username").val())) { alert("姓名不能为空！"); return false; }
				     if(isEmpty($("#tel").val())) { alert("联系方式不能为空！"); return false; }
				     if( !(isMobile($("#tel").val()) || isTel($("#tel").val())) ) { alert("联系方式不符合要求！"); return false; }
				     if(isEmpty($("#lv").val())) { alert("请选择评估等级！"); return false; }
				     
				     if(!isEmpty($("#cname").val())) { 
				    	 if(isEmpty($("#trade").val())) { alert("请选择客户行业！"); return false; }
				     }
				     
				     
				     return true;
			   }
			
			   function process(responseJson) {
			     if(responseJson.code == 0) {
			         $('#error_label').text("错误信息：修改失败");
			         $("#p_error").show();
			         return;
			     }
			     else
			     { 
			    	 location.href = "<%=basePath%>wall/list.do";
			     }
			   }  
	  });
	 
	   //返回列表页面
	   function btn_return(){
	    	window.location.href="<%=basePath%>wall/list.do";
	}

	function calcArea() {
		var high = $("#high").val();
		var width = $("#width").val();
		if (isNaN(high) || isNaN(width)) {
			if (isNaN(high))
				$("#high").val("");
			if (isNaN(width))
				$("#width").val("");
			$("#area").val("");
			return false;
		}
		$("#area").val(high * width);
	}

	function showFiles() {
		$("#fileQueue").empty();
		var fileStr = $("#images").val();
		var fileHtml = "";
		var arr = fileStr.split(";");
		for (var i = 0; i < arr.length; i++) {
			fileHtml = fileHtml + "<p>" + arr[i] + "</p>";
		}
		$("#fileQueue").append(fileHtml);
	}

	function showWcEntity() {
		$("#cname").val("福建青年墙体户外传播");
		$("#cname").attr("readonly", "readonly");
		$("#trade").val("4");
		$("#trade").attr("readonly", "readonly");
	}

	function clearSelect() {
		$("#cname").val("");
		$("#cname").removeAttr("readonly");
		$("#trade").val("");
	}

	function init() {
		var province = $("#province").val();
		var city = $("#city").val();
		var county = $("#county").val();
		var json = eval("(" + shiData + ")");
		if (province == "" || province == "福建") {
			province = "福建省";
			str = '<option value="'+province+'" >' + province + ' </option>';
			$("#province").append(str);
			return;
		}
		var citys = json[province];
		$(citys).each(
				function(i) {
					var c = citys[i];
					if (c.id == city)
						str = '<option value="'+c.id+'" selected >' + c.name
								+ ' </option>';
					else
						str = '<option value="'+c.id+'"  >' + c.name
								+ ' </option>';
					$("#city").append(str);
				});

		json = eval("(" + xianData + ")");
		var countys = json[city];
		$(countys).each(
				function(i) {
					var co = countys[i];
					if (co.id == county)
						str = '<option value="'+co.id+'" selected >' + co.name
								+ ' </option>';
					else
						str = '<option value="'+co.id+'"  >' + co.name
								+ ' </option>';
					$("#county").append(str);
				});
	}
</script>
</head>
<body onload="init();">

	<fieldset>
		<div style="width: 45%; float: left;">
			<legend>修改墙体：</legend>
			<form id="wallForm" method="post" action="wall/update.do">
				<input id="id" name="id" type="hidden" value="${wall.id}" /> 
				<input id="wid" name="wid" type="hidden" value="${wall.id}" /> 
				<input id="wcid" name="wcid" type="hidden" value="${wcEntity.id}" /> 
				<input id="images" name="images" type="hidden" value="${wall.images}" />
				<input name="locationX" type="hidden" value="${wall.locationX }" />
				<input name="locationY" type="hidden" value="${wall.locationY }" />
				<p id="p_error" style="margin: 10px 10px;">
					<label id="error_label" style="color: red;"></label>
				</p>
				<table>
					<tr>
						<td><label for="province">省-市-县：</label></td>
						<td><select style="width: 100px;" id="province"
							name="province" onchange="selectSheng()">
								<option value="${wall.province }">${wall.province }</option>
						</select> - <select style="width: 100px;" id="city" name="city"
							onchange="selectShi();">
								<option value="${wall.city }">${wall.city }</option>
						</select> - <select style="width: 100px;" id="county" name="county">
								<option value="${wall.county }">${wall.county }</option>>
						</select></td>
					</tr>
					<tr>
						<td><label for="town">乡镇：</label></td>
						<td><input type="text" name="town" id="town"
							value="${wall.town }" /></td>
					</tr>
					<tr>
						<td><label for="address">地址：</label></td>
						<td><input type="text" name="address" id="address"
							value="${wall.address }" /></td>
					</tr>
					<tr>
						<td><label for="bugLevel">规格：</label></td>
						<td>高<input type="text" name="high" id="high"
							style="width: 30px;" onkeyup="calcArea();" value="${wall.high }" />(m)*
							宽<input type="text" name="width" id="width" style="width: 30px;"
							onkeyup="calcArea();" value="${wall.width }" />(m)= 面积<input
							type="text" name="area" id="area" style="width: 30px;"
							readonly="readonly" value="${wall.area }" />(m^2)
						</td>
					</tr>
					<tr>
						<td><label for="status">姓名：</label></td>
						<td><input type="text" name="username" id="username"
							value="${wall.username }" /></td>
					</tr>
					<tr>
						<td><label for="status">电话：</label></td>
						<td><input type="text" name="tel" id="tel"
							value="${wall.tel }" /></td>
					</tr>
					<tr>
						<td><label for="status">租赁类别：</label></td>
						<td><input id="nothing" type="radio" class="" name="status"
							value="0"
							<c:if test="${wall.status eq 0}">checked="checked"</c:if>
							onclick="clearSelect();" /><label>空白</label> <input id="self"
							type="radio" class="" name="status" value="1"
							<c:if test="${wall.status eq 1}">checked="checked"</c:if>
							onclick="showWcEntity();" /><label>自租</label> <input id="other"
							type="radio" class="" name="status" value="2"
							<c:if test="${wall.status eq 2}">checked="checked"</c:if>
							onclick="clearSelect();" /><label>他租</label></td>
					</tr>
					<tr>
						<td><label for="status">客户名称：</label></td>
						<td><input type="text" name="cname" id="cname"
							value="${wcEntity.cname }" /></td>
					</tr>
					<tr>
						<td><label for="status">行业列表：</label></td>
						<td><select id="trade" name="trade" style="width: 100px;">
								<option value="" style="color: red;">--选择行业--</option>
								<c:forEach var="trade" items="${tradeList }">
									<option value="${trade.itemName }"
										<c:if test="${trade.itemName eq wcEntity.trade}">selected="selected"</c:if>>${trade.itemValue }</option>
								</c:forEach>
						</select></td>
					</tr>

					<tr>
						<td><label for="rentTime">租赁时间：</label></td>
						<td><input type="text" name="rentTime" id="rentTime"
							onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" class="Wdate"
							value="${wcEntity.rentTime }" /></td>
					</tr>

					<tr>
						<td><label for="endTime">到期时间：</label></td>
						<td><input type="text" name="endTime" id="endTime"
							onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'rentTime\')}'})"
							class="Wdate" value="${wcEntity.endTime }" /></td>
					</tr>
					<tr>
						<td><label for="status">价格：</label></td>
						<%-- 				<td><input type="text" name="price" id="price" value="${wall.price }" /></td> --%>
						<td><input onkeyup="value=value.replace(/[^\d]/g,'') "
							type="text" name="price" id="price" value="${wall.price }"
							onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" /></td>
					</tr>

					<tr>
						<td><label for="lv">评估等级</label></td>
						<td><select id="lv" name="lv" style="width: 100px;">
								<option value="" style="color: red;">--选择等级--</option>
								<option value="0"
									<c:if test="${wall.lv eq 0}">selected="selected"</c:if>>--优--</option>
								<option value="1"
									<c:if test="${wall.lv eq 1}">selected="selected"</c:if>>--良--</option>
								<option value="2"
									<c:if test="${wall.lv eq 2}">selected="selected"</c:if>>--中--</option>
						</select></td>
					</tr>
					<tr>
						<td><label for="status">备注：</label></td>
						<td><input type="text" name="memo" id="memo"
							value="${wall.memo }" /></td>
					</tr>
					<tr>
						<td></td>
						<td><input type="submit" id="btn_insert" value="提交"
							style="width: 80px;" /> <input type="button" id="btn_back"
							value="返回" onclick="btn_return();" style="width: 80px;" /></td>
					</tr>
				</table>
			</form>
		</div>
	</fieldset>

</body>
</html>